<?php
/**
 * Form Error View Helper
 * The Zend Framework comes with a formError() view helper, but I don't really
 * care for the way it works. I have extended it to allow setting a static
 * variable with all form errors in the controller and then calling formError
 * with a single field name when needing to render errors. I don't love the use
 * of static methods/properties for this, but it works for now.
 *
 * @package 	Visi
 * @subpackage 	View Helpers
 * @author 		Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright 	Luke Visinoni <luke.visinoni@gmail.com>
 * @version 	$Id$
 * @todo        Look into another way to do this (without using static)
 */
class Visi_View_Helper_FormError extends Zend_View_Helper_FormErrors {

    static protected $_errors = array();
    
    public function formError($field, array $options = null) {
    
        $errors = array_key_exists($field, self::$_errors) ?
            self::$_errors[$field] :
            array();
        return parent::formErrors($errors, $options);
    
    }
    
    static public function setErrors(array $errors) {
    
        self::$_errors = $errors;
    
    }

}